package cc.rengu.igas.route.common.dao.impl;

import cc.rengu.igas.route.common.dao.OpmsCupsMchntInfoMapper;
import cc.rengu.igas.route.common.entity.OpmsCupsMchntInfo;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.dbs.Database;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * 银联商户信息表操作实现
 * <p>
 * Copyed by xlz from opms on 2020/3/20.
 *
 * @author xlz
 * @version 1.0
 * @date 2020-04-27
 */
public class OpmsCupsMchntInfoMapperImpl implements OpmsCupsMchntInfoMapper {

    RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MCMP_POOL_NAME);

    @Override
    public OpmsCupsMchntInfo selectCupsMchntInfoByInstIdMchntNo(String instId, String mchntNo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MCMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "RouteGetCupsMchntInfoByInstIdMchntNo");

        OpmsCupsMchntInfo info = new OpmsCupsMchntInfo();
        info.setInstId(instId);
        info.setMchntNo(mchntNo);

        int recode = dbsUtil.dbsExecuteSql(sqlStr, info, info);
        if (Database.DBS_NOT_FOUND == recode) {
            rglog.info("银联商户信息表不存在该数据，instId:<{}>,mchntNo:<{}>", instId, mchntNo);
            return null;
        } else if (Database.DBS_SUCCESS != 0) {
            rglog.info("查询银联商户信息表失败，instId:<{}>,mchntNo:<{}>,recode:<{}>", instId, mchntNo, recode);
            return null;
        }

        return info;
    }
}
